package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.ClipboardUtils;
import com.blankj.utilcode.util.ToastUtils;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityIdCardRecBinding;
import stark.common.apis.base.OcrIdCardRet;
import stark.common.basic.event.EventStatProxy;

public class IdCardRecActivity extends BaseAc<ActivityIdCardRecBinding> {

    public static Bitmap sBitmap;
    public static OcrIdCardRet sIdCardRet;

    @Override
    protected int onCreate() {
        return R.layout.activity_id_card_rec;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);
        mDataBinding.ivIdCardRecBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.tvName.setText(sIdCardRet.words_result.name.words == null ? "" : sIdCardRet.words_result.name.words);
        mDataBinding.tvGender.setText(sIdCardRet.words_result.gender.words == null ? "" : sIdCardRet.words_result.gender.words);
        mDataBinding.tvNation.setText(sIdCardRet.words_result.nation.words == null ? "" : sIdCardRet.words_result.nation.words);
        mDataBinding.tvBirth.setText(sIdCardRet.words_result.birthDate.words == null ? "" : sIdCardRet.words_result.birthDate.words);
        mDataBinding.tvAddress.setText(sIdCardRet.words_result.address.words == null ? "" : sIdCardRet.words_result.address.words);
        mDataBinding.tvId.setText(sIdCardRet.words_result.idNumber.words == null ? "" : sIdCardRet.words_result.idNumber.words);
        if (sIdCardRet.words_result.startDate == null) {
            mDataBinding.tvSign.setText("");
        } else {
            mDataBinding.tvSign.setText(sIdCardRet.words_result.signOrg.words);
        }
        if (sIdCardRet.words_result.startDate == null || sIdCardRet.words_result.endDate.words == null) {
            mDataBinding.tvIndate.setText("");
        } else {
            mDataBinding.tvIndate.setText(sIdCardRet.words_result.startDate.words + "—" + sIdCardRet.words_result.endDate.words);
        }
        mDataBinding.ivCopy.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivCopy:
                String content = getString(R.string.name_text) + sIdCardRet.words_result.name.words + "\n" + getString(R.string.gender_text) + sIdCardRet.words_result.gender.words + "\n" + getString(R.string.nation_text) + sIdCardRet.words_result.nation.words + "\n" + getString(R.string.birth_text) + sIdCardRet.words_result.birthDate.words + "\n" + getString(R.string.address_text) + sIdCardRet.words_result.address.words + "\n" + getString(R.string.id_text) + sIdCardRet.words_result.idNumber.words + "\n";
                ClipboardUtils.copyText(content);
                ToastUtils.showShort(getString(R.string.copy_success_tips));
                break;
        }
    }

    @Override
    protected void initData() {
        mDataBinding.ivResultImg.setImageBitmap(sBitmap);
    }
}